﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
//using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using ADESSA.Entities;
using ADESSA.Business;
using FetCo.Data;
using FetCo.Framework;

public partial class NewDetail : System.Web.UI.Page
{
    private Article article;
    private long articleId;
    private void getArticle(long id)
    {
        article = ArticleService.GetArticle(id);
    }
    #region Load nội dung của tin tức
    private void loadContent()
    {
        ltrTitle.Text = article.Title;
        ltrContent.Text = article.Content;
        img.ImageUrl = article.Image;
    }
    #endregion

    #region Load các tin khác
    private void loadOtherNews()
    {
        int i = 10;
        Criteria cri = new Criteria();
        cri.add(Article._Table + "." + ArticleColumns.SubCatId, article.SubCatId, Condition.EQUAL, Condition.AND);
        ArticleCollection _ArticleCollection = ArticleService.GetArticleListByParam(ArticleColumns.CreatedDate, OrderDirection.DESC, 1, i, cri.Criter, out i);
        if (_ArticleCollection.Count > 0)
        {
            rptOtherNews.DataSource = _ArticleCollection;
            rptOtherNews.DataBind();
        }

    }

    protected void rptOtherNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Literal ltrTitle = (Literal)e.Item.FindControl("ltrTitle");
        Literal ltrSum = (Literal)e.Item.FindControl("ltrSum");
        Article art = (Article)e.Item.DataItem;
        ltrTitle.Text = art.Title;
        ltrSum.Text = art.Summary;
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        
            if (Request.QueryString["ArticleId"] != null)
            {
                articleId = long.Parse(Request.QueryString["ArticleId"].ToString());
                getArticle(articleId);
                loadContent();
                loadOtherNews();
            }
        }

    
}
